#!/bin/bash

randomNum() {
	if [ $# -eq 1 ];then
		(( rand = $RANDOM*$1/32767 ))
		echo $rand
	else
		echo $RANDOM
	fi
}

completar() {
	formedNumber=""
	if [ $# -eq 2 ];then
		(( max = $2 - 1 ))

		for (( i = $max; i >= 0; i-- ))
		do
			((tenth = 10 ** $i))
			if [ $1 -lt $tenth ];then
				formedNumber=$formedNumber"0"
			else
				formedNumber=$formedNumber"$1"
				break;
			fi
		done
		echo $formedNumber
	else
		echo "maaaaaaaal"
	fi
}

genRegistro() {
	codCliente=CLIENTE
	codArea=AREA
	nroLinea=
	promedio=
	opLocal=TASA
	iur=S
	opInt=TASA
	int=S
	opADSL=TASA
	territorio=Centro
	tipoTerritorio=Country
	catAbono=Com
	catCliente=CF


	
	var=`randomNum 999`
	var=`completar $var 3`
	codCliente=$codCliente$var


	var=`randomNum 15`
	(( var = var + 1 ))
	var=`completar $var 6`
	codArea=$codArea$var


	var=`randomNum 9999999999`
	var=`completar $var 10`
	nroLinea=$var

	var=`randomNum 999999`
	var=`completar $var 10`
	promedio=$var

	var=`randomNum 3`
	if [ $var -eq 1 ];then
		opLocal=TECO
	elif [ $var -eq 2 ];then
		opLocal=Otro
	fi

	var=`randomNum 2`
	if [ $var -eq 1 ];then
		iur=N
	fi

	var=`randomNum 3`
	if [ $var -eq 1 ];then
		opInt=TECO
	elif [ $var -eq 2 ];then
		opInt=Otro
	fi

	var=`randomNum 2`
	if [ $var -eq 1 ];then
		int=N
	fi

	var=`randomNum 4`
	if [ $var -eq 1 ];then
		opADSL=TECO
	elif [ $var -eq 2 ];then
		opADSL=Otro
	elif [ $var -eq 3 ];then
		opADSL=Ninguna
	fi

	var=`randomNum 4`
	if [ $var -eq 1 ];then
		territorio=GBANor
	elif [ $var -eq 2 ];then
		territorio=GBASur
	elif [ $var -eq 3 ];then
		territorio=GBAOes
	fi

	var=`randomNum 4`
	if [ $var -eq 1 ];then
		tipoTerritorio=Delta
	elif [ $var -eq 2 ];then
		tipoTerritorio=Rural
	elif [ $var -eq 3 ];then
		tipoTerritorio=Std
	fi

	var=`randomNum 3`
	if [ $var -eq 1 ];then
		catAbono=Jub
	elif [ $var -eq 2 ];then
		catAbono=Res
	fi

	var=`randomNum 4`
	if [ $var -eq 1 ];then
		catCliente=MO
	elif [ $var -eq 2 ];then
		catCliente=RI
	elif [ $var -eq 3 ];then
		catCliente=EX
	fi

	registro=$codCliente","$codArea","$nroLinea","$promedio","$opLocal","$iur","$opInt","$int","$opADSL","$territorio","$tipoTerritorio","$catAbono","$catCliente

	echo $registro
}

if [ $# -lt 1 ];then
	echo "se debe indicar la cantidad de registros a crear"
	exit 1
fi


for (( i = 0 ; i < $1 ; i++ ))
do
	registro=`genRegistro`
	echo $registro
done

